﻿--[[
   @brief    游戏更新磁盘空间不足tips
   @author   hqzheng
   @version  1.0
   @date     2017-03-17
--]]

-- 注意：后续请尽量使用通用tips组件 ui_utility.show_tips(param);

GameUpdateLackSpaceTips = {

};

GameUpdateLackSpaceEventListener = {
};

function GameUpdateLackSpaceTips:new(parent_id, game_id)
    local o = {tips_id_ = parent_id, game_id_ = game_id};
    setmetatable(o, self);
    self.__index = self;
    o:init();
    return o;
end

function GameUpdateLackSpaceTips:init()
    self:log("init");
    self.tips_ctrl_ptr_ = ui_utility.get_ctrl_ptr_by_id(self.tips_id_);
end

function GameUpdateLackSpaceTips:log(msg, core_msg)
    base_utility.log(string.format("[GameOffShellTips] %s", msg), core_msg);
end

function GameUpdateLackSpaceTips:show(is_show)
    self:log(string.format("show, is_show:%s", tostring(is_show)));

    if self.tips_ctrl_ptr_ == nil then
        self:log("show, banner_ctrl_ptr_ is nil");
        return; 
    end

    if true == is_show then
        self.tips_ctrl_ptr_:MoveToCenter();
        self.tips_ctrl_ptr_:BringToTop();
        self.tips_ctrl_ptr_:Show(TRUE);
        self:data_report("tips_show");
    elseif false == is_show then
        self.tips_ctrl_ptr_:Show(FALSE); 
    end
end

function GameUpdateLackSpaceTips:set_update_info(server_id)
    self:log(string.format("[set_update_info]server_id:%d", server_id));
    self.server_id_ = server_id;
end

function GameUpdateLackSpaceTips:get_game_id()
    return self.game_id_;
end

function GameUpdateLackSpaceTips:update_game()
    local action_info = {
        game_id_ = self.game_id_,
        zone_id_ = self.server_id_,
        uid_ = 0,
        launch_op_from = ierd_tgp.game_library.LAUNCH_OP_FROM_LACK_SPACE_TIPS
    };

    WGGameAction.excute_action(GameActions.kUpdateGame, action_info);
    self:show(false);
end

function GameUpdateLackSpaceTips:data_report(sub_action)
    self:log(string.format("[ok_btn_click_report]sub_action:%s", sub_action));
    local report_data = ierd_tgp.tpf_ui.LuaQosDataEx:new();
    local pv_data = {};

    if nil ~= report_data then
        pv_data["game_id"] = self.game_id_;
        report_data.oc_type = 1;
        report_data.qos_kind = ierd_tgp.adapt_for_imports.qos.Qos_kind.kGameUpdateLackSpace;
        report_data.str_action = "game_update_lack_space_tips"
        report_data.str_type = sub_action;
        report_data.str_json = base_utility.table_to_json(pv_data);
        report_data.game_id = self.game_id_;
            
        base_utility.lua_qos_ex(report_data);
        report_data:delete();
    end
end
------------------------------GameUpdateLackSpaceEventListener------------------------------------------------
function GameUpdateLackSpaceEventListener.update_game(uilib, control_id, x, y)
    base_utility.log(string.format(
        "[GameUpdateLackSpaceEventListener]update_game ctrl_id:%d", control_id));
    
    local ctrl_id = ui_utility.get_ctrl_parent_id(control_id);
    local tips = banner_model.get_lack_space_tips(ctrl_id);
    if nil == tips then
        base_utility.log(string.format(
            "[GameUpdateLackSpaceEventListener][update_game]tips is NIL,"..
            " ctrl_id:%d", control_id), true);
        return;
    end
    
    tips:update_game();
    tips:data_report("update_btn_click");
end

function GameUpdateLackSpaceEventListener.close_tips(uilib, control_id, x, y)
    base_utility.log(string.format(
        "[GameUpdateLackSpaceEventListener]close_tips ctrl_id:%d", control_id));
    
    local title_bar_id = ui_utility.get_ctrl_parent_id(control_id);
    local tips_ctrl_id = ui_utility.get_ctrl_parent_id(title_bar_id);
    local tips = banner_model.get_lack_space_tips(tips_ctrl_id);

    if nil == tips then
        base_utility.log(string.format(
            "[GameUpdateLackSpaceEventListener][close_tips]tips is NIL,"..
            " ctrl_id:%d", control_id), true);
        return;
    end
    
    tips:show(false);
    tips:data_report("close_btn_click");
end

function GameUpdateLackSpaceEventListener.click_ok_btn(uilib, control_id, x, y)
    base_utility.log(string.format(
        "[GameUpdateLackSpaceEventListener]click_ok_btn ctrl_id:%d", control_id));
    
    local tips_ctrl_id = ui_utility.get_ctrl_parent_id(control_id);
    local tips = banner_model.get_lack_space_tips(tips_ctrl_id);

    if nil == tips then
        base_utility.log(string.format(
            "[GameUpdateLackSpaceEventListener][click_ok_btn]tips is NIL,"..
            " ctrl_id:%d", control_id), true);
        return;
    end
    
    tips:show(false);
    tips:data_report("ok_btn_click");
end

